package com.sina.shop.domain.foot;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.sina.shop.core.domain.Domain;
import com.sina.shop.domain.Status;
import com.sina.shop.domain.admin.Admin;
import com.sina.shop.domain.goods.Goods;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import javax.validation.constraints.Min;
import java.time.LocalDateTime;

/**
 * Created with IntelliJ IDEA.
 * Description: 用户足迹实体类
 * 段浩杰   2017-12-11-14:40
 */
@Entity
@Table(name = "tb_foot")
@DynamicInsert
@DynamicUpdate
public class Foot extends Domain {

    @Id
    @Column(name = "id", updatable = false)
    @GenericGenerator(name = "sequence_id", strategy = "com.sina.shop.sequence.IdGenerator")
    @GeneratedValue(generator = "sequence_id")
    @Min(1)
    private Long id;//主键

    @ManyToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    @JoinColumn(name = "aid")
    private Admin admin;//所属用户

    @OneToOne
    @JoinColumn(name = "gid")
    private Goods goods;//浏览的商品

    @Column(name = "create_time")
    @ColumnDefault("CURRENT_TIMESTAMP")
    @DateTimeFormat(pattern = "uuuu-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)//此注解是为了解决feign远程调用中出现的LocalDateTime不能序列化问题
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime createTime;//创建时间

    @Enumerated(EnumType.STRING)
    @Column(name = "status", length = 10)
    private Status status;//状态（用来标记性删除）

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Admin getAdmin() {
        return admin;
    }

    public void setAdmin(Admin admin) {
        this.admin = admin;
    }

    public Goods getGoods() {
        return goods;
    }

    public void setGoods(Goods goods) {
        this.goods = goods;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }
}
